package fitnesshub.controller;

import fitnesshub.pojo.dto.AddConsumptionRecordDTO;
import fitnesshub.pojo.dto.ConsumptionRecordPageQueryDTO;
import fitnesshub.result.PageResult;
import fitnesshub.result.Result;
import fitnesshub.service.ConsumptionRecordService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 消费记录管理
*/
@RestController
@Slf4j
@RequestMapping("/admin/consumption")
public class ConsumptionRecordController {
    @Autowired
    private ConsumptionRecordService consumptionRecordService;

    /**
     * 消费记录分页
     * @return
     */
    //alt+enter快捷创建对象
    @GetMapping("/page")
    public Result<PageResult> page(ConsumptionRecordPageQueryDTO consumptionRecordPageQueryDTO) {
        log.info("消费记录分页查询，参数：{}", consumptionRecordPageQueryDTO);
        PageResult pageResult = consumptionRecordService.page(consumptionRecordPageQueryDTO);
        return Result.success(pageResult);
    }
    /**
     * 添加消费记录
     * @param addConsumptionRecordDTO
     * @return
     */
    @PostMapping
    public Result save(@RequestBody AddConsumptionRecordDTO addConsumptionRecordDTO) {
        log.info("添加消费记录：{}", addConsumptionRecordDTO);
        consumptionRecordService.addConsumptionRecord(addConsumptionRecordDTO);
        return Result.success();
    }
}
